/*
 * @(#)VandaException.java 1.0 2005-3-7
 * Copyright 2005 VandaGroup, Inc. All rights reserved.
 */
package com.vanda.exception;

import java.util.List;

import com.vanda.util.LogFunc;



/*******
 * 类说明:
 * Exception基类，系统中所有Exception应从此类派生。
 * 采用统一的异常处理，公开方法应只抛出此类异常。
 * <P>@author wkf3915
 * <P>@version 1.0 2005-3-7
 */
public class VandaException extends NestableException {

	//保留异常信息栈，因为从EJB抛出异常的信息栈丢失
	private String stackTrace;
	private String strErrCode = "";
	protected Object[] params;
	
	private List lstErrCodes = null;
	
	private List lstParams = null;
	
	public VandaException() {
		super();
	}
	
	public VandaException(String msg) {
		super(msg);
	}
	
	public VandaException(String msg, String sParam) {
		super(msg);
		params = new Object[1];
		params[0] = sParam;
	}
	
	public VandaException(String msg, String sParam1, String sParam2) {
		super(msg);
		params = new Object[2];
		params[0] = sParam1;
		params[1] = sParam2;
	}
	
	public VandaException(String msg, Object[] sParams) {
		super(msg);
		params = sParams;
	}
	
	public VandaException(Throwable cause) {
		super(cause);
	}
	
	public VandaException(String msg, Throwable cause) {
		super(msg,cause);
	}
	
	public String getMessage(){
		String[] msgs = getMessages();
		StringBuffer buffer = new StringBuffer();
		for(int i=0;i<msgs.length;i++){
			if(msgs[i] != null && buffer.toString().indexOf(msgs[i]) < 0)
			    // Modified by Angus Yao 2005-08-20 14:04
				// FROM
			    // buffer.append(msgs[i]).append("<br>");
			    // TO
				buffer.append(msgs[i]);
		}
		return buffer.toString();
	}
	
	public String getStrErrCode() {
		return this.strErrCode;
	}
	
	public void setStrErrCode(String strErrCode) {
		this.strErrCode = strErrCode;
	}
	
	public Object[] getParams(){
		return params;
	}
    
    public void printStackTrace() {
        // remove this method when need to print stack trace for debug
        LogFunc.error(this);
    }
	/**
	 * @return 返回 lstErrCodes。
	 */
	public List getLstErrCodes() {
		return lstErrCodes;
	}
	/**
	 * @param lstErrCodes 要设置的 lstErrCodes。
	 */
	public void setLstErrCodes(List lstErrCodes) {
		this.lstErrCodes = lstErrCodes;
	}
	/**
	 * @return 返回 lstParams。
	 */
	public List getLstParams() {
		return lstParams;
	}
	/**
	 * @param lstParams 要设置的 lstParams。
	 */
	public void setLstParams(List lstParams) {
		this.lstParams = lstParams;
	}
}
